import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;

public abstract class Creature extends Entity 
{
	protected float speed;
	protected Vector2 dir;
	protected Boolean dead = false;
	
	protected Point healthPosition;
	protected int healthWidth = 20;
	
 	public Creature(Vector2 position, Vector2 dir)
	{
		this.position = position;
		this.dir = dir;
	}

	// Update method
	public void Update()
	{
		position.Add(Vector2.Multiply(dir, speed));
	}
	
	// Draw method
	public void Draw(Graphics g)
	{
		// Draws the tower
		g.setColor(color);
		g.drawRect((int)position.x, (int)position.y, size, size);
		
		DrawHealth(g);
	}
	
	// Draws the health bar
	void DrawHealth(Graphics g)
	{
		// Color of the bar, depending on the creature's life
		if(life <= maxLife /3)
			g.setColor(Color.red);
		else if(life <= (maxLife * 2)/3)
			g.setColor(Color.orange);
		else
			g.setColor(Color.green);
		
		g.fillRect((int)position.x - healthWidth/2 + size/2, (int)position.y - 10, (healthWidth * life)/maxLife, 5);
	}
	
	public void DealDamage(int damage, Tower attacker)
	{
		if(life - damage <= 0)
		{
			life = 0;
			dead = true;
			attacker.kills++;
		}
		else
			life -= damage;
	}

	public String GetType()
	{
		return "creature";
	}
	
	// Getter & setter
	public Boolean getDead() {return dead;}
	public void setDead(Boolean dead) {this.dead = dead;}
	
}
